<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_commission extends Controller_Abstract {
	
	/**
	 * 佣金列表
	 */
	function actionIndex()
	{
		//关联表
		$this->union_table = fxcommission::meta();
        //获取搜索参数
        $this->get_param();
        //初始化分页信息
        $this->_format_page_info();
        $append_data = array('acct_id'=>$_SESSION['acct']['id']);

        if (!is_null($append_data))$this->param = array_merge($this->param,$append_data);
        
        $dis_param = new helper_disposeparam($this->param);
        $sql = $dis_param->getsql();//OUT PUT用
        //dump($sql);die;
        $_SESSION['lastsql'] = $sql;//OUT PUT用
        $obj = call_user_func_array(array($this->union_table,'find'), $sql);
        $item = $obj->limitPage($this->curr_page,$this->page_size)
                    ->order(' '.$this->orderkey.' '.$this->ordertype)
                    ->fetchPagination($this->pagination)
                    ->asArray()
                    ->getall();
        for ($i=0; $i < count($item); $i++) { 
            $userinfo = acctuser::getuserinfo($item[$i]['user_id']);
            $objuserinfo = acctuser::getuserinfo($item[$i]['object_uid']);
            $item[$i]['nickname'] = $userinfo['nickname'];
            $item[$i]['objnickname'] = $objuserinfo['nickname'];
            $item[$i]['user_id'] = $userinfo['id'];
        }
        $this->_view['item'] = $item;
        $this->_view['pagination'] = $this->pagination;
        $this->_view['orderField'] = $this->orderkey;
        $this->_view['orderDirection'] = $this->ordertype;
	}
	 
	/**
	 * 佣金列表
	 */
	 
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = fxcommission::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_fxcommission_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );

	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加视频标签,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑视频标签,id :' . $handle->form_database_obj->id );
	        }
	         
	        if($handle->status=='success')
	            $this->_context->forwardUrl = url("fxcommission/index");
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }
	     
	}
	 
	/**
	 * 佣金列表
	 */
	function actionDel() {
	     Syslog::logs("删除视频标签，ID：".print_r($this->_context->ids,true));
	     $this->union_table = fxcommission::meta();
	     $this->delete(array('id'=>$this->_context->ids));    	  
	}


}


